<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */

class b2c_ctl_admin_goods_tip extends desktop_controller{
    var $workground = 'b2c_ctl_admin_goods';

    public function __construct($app){
        parent::__construct($app);
        header("cache-control: no-store, no-cache, must-revalidate");
    }

    function index(){
        if($this->has_permission('editgoods')){
            $custom_actions[] = array('label'=>app::get('b2c')->_('添加发货仓'),'href'=>'index.php?app=b2c&ctl=admin_goods_tip&act=add','target'=>'dialog::{title:\''.app::get('b2c')->_('添加发货仓').'\',width:800,height:600}');
        	$actions_base['use_buildin_export'] = true;
        }else{
			$custom_actions=array();
			$actions_base['use_buildin_recycle'] = false;
		}
        $actions_base['title'] = app::get('b2c')->_('发货仓管理');
        $actions_base['actions'] = $custom_actions;
        $actions_base['use_view_tab'] = true;
        $this->finder('b2c_mdl_goods_tip',$actions_base);
    }
	
    function add(){
        if($this->has_permission('editgoods')){
			$this->pagedata['dlytype']=app::get('b2c')->model('dlytype')->getList('dt_id,dt_name',array('dt_status'=>'1'),0,-1,'ordernum ASC');
			$this->pagedata['payments']=app::get('ectools')->model('payment_cfgs')->getList('app_id,app_name');
			$this->display('admin/goods/tip_edit.html');
		}
    }
	
    function edit($tip_id){
        if($this->has_permission('editgoods')){
			$row=app::get('b2c')->model('goods_tip')->getRow('*',array('tip_id'=>$tip_id));
			$this->pagedata['tip']=$row;
			$this->pagedata['tip']['values']=explode('#!!#',$row['tip_text']);
			$this->pagedata['dlytype']=app::get('b2c')->model('dlytype')->getList('dt_id,dt_name',array('dt_status'=>'1'),0,-1,'ordernum ASC');
			if(!empty($row['dt_ids'])){
				$dt_id_arr = strstr($row['dt_ids'],',')?explode(',',$row['dt_ids']):array($row['dt_ids']);
				$this->pagedata['tip']['dt_id_arr']=array_flip($dt_id_arr);
			}else{
				$this->pagedata['tip']['dt_id_arr'] = array();
			}
			
			$this->pagedata['payments']=app::get('ectools')->model('payment_cfgs')->getList('app_id,app_name');
			if(!empty($row['payment_app_ids'])){
				$payment_app_id_arr = strstr($row['payment_app_ids'],',')?explode(',',$row['payment_app_ids']):array($row['payment_app_ids']);
				$this->pagedata['tip']['payment_app_id_arr']=array_flip($payment_app_id_arr);
			}else{
				$this->pagedata['tip']['payment_app_id_arr'] = array();
			}
			
			
			
			$this->display('admin/goods/tip_edit.html');
		}
    }
	
    function save(){
        if($this->has_permission('editgoods')){
			$tip['tip_id']=$_POST['tip_id'];
			$tip['tip_name']=$_POST['tip_name'];
			$tip['ordernum']=$_POST['ordernum'];
			$tip['dt_ids']=implode(',',$_POST['dt_ids']);
			$tip['payment_app_ids']=implode(',',$_POST['payment_app_ids']);
			$tip['need_idcard']=$_POST['need_idcard'];
			$tip['amount_max']=$_POST['amount_max'];
			if ($_POST['values']) {
				$tip['tip_text']=implode('#!!#',$_POST['values']);
			} else {
				$tip['tip_text'] = '';
			}
						
			$this->begin('index.php?app=b2c&ctl=admin_goods_tip&act=index');	
			$mdl_goods_tip=app::get('b2c')->model('goods_tip');
			if($mdl_goods_tip->save($tip)){
				$this->end(true,app::get('b2c')->_('保存成功'));
			}else{
				$this->end(false,app::get('b2c')->_('保存失败'));
			}
			
		}
    }
}
